using Microsoft.AspNetCore.Mvc;
using ZeroBlog.Application.FlashArticles;
using ZeroBlog.Application.FlashArticles.Dtos.In;
using ZeroBlog.Application.FlashArticles.Dtos.Out;
using ZeroBlog.Application.FlashArticles.Dtos.Query;
using ZeroSum.Models;

namespace ZeroBlog.Api.Controllers;

[ApiController]
[Route("[controller]/[action]")]
public class FlashArticleController : ControllerBase
{
    private readonly IFlashArticleApplicationService _applicationService;

    public FlashArticleController(IFlashArticleApplicationService applicationService)
    {
        _applicationService = applicationService;
    }

    [HttpGet]
    public async Task<PagedResponseModel<PageFlashArticleDto>> Page([FromQuery] PageFlashArticleQuery query)
    {
        return await _applicationService.Page(query);
    }

    [HttpPost]
    public async Task Add([FromBody] AddFlashArticleDto dto)
    {
        await _applicationService.AddAsync(dto);
    }

    [HttpPost]
    public async Task Delete([FromBody] DeleteFlashArticleDto dto)
    {
        await _applicationService.DeleteAsync(dto);
    }

    [HttpPost]
    public async Task Update([FromBody] UpdateFlashArticleDto dto)
    {
        await _applicationService.UpdateAsync(dto);
    }

    [HttpGet]
    public async Task<DetailFlashArticleDto> Detail([FromQuery] DetailFlashArticleQuery query)
    {
        return await _applicationService.Detail(query);
    }
}